package bpm.dao.impl.archive;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.archive.ArchiveField;
import bpm.domain.document.Field;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class ArchiveFieldMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		ArchiveField field = new ArchiveField();
		
		field.setId(rs.getInt("id"));
		field.setKey(rs.getString("key"));
		field.setName(rs.getString("name"));
		field.setDataType(rs.getString("data_type"));
		field.setEditStyle(rs.getInt("edit_style"));
		field.setEditArgument(rs.getString("edit_argument"));
		field.setDisplayArgument(rs.getString("display_argument"));
		
		java.sql.Date createTime = rs.getDate("create_time");
		if(createTime != null) {
			field.setCreateTime(new Date(createTime.getTime()));
		}
		
		field.setDescription(rs.getString("description"));
		
		String documentFieldKey = rs.getString("doc_field_key");
		if(documentFieldKey != null) {
			Field docField = new Field();
			docField.setKey(documentFieldKey);
			field.setDocumentField(docField);
		}
		
		field.setInputString(rs.getString("input"));
		field.setEnableString(rs.getString("enable"));
		field.setDefaultValue(rs.getString("default_value"));
		field.setParentXmlElement(rs.getString("parent_xml_element"));
		
		return field;
	}

}
